/*
 ------------------------------------------------------------------------------
 Copyright (C) 1996-2001 Id Software, Inc.

 This file is part of the Quake source code.

 The Quake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// random.h - random math library
//


#ifndef __MATH_RANDOM_H__
#define __MATH_RANDOM_H__


class glqRandom {
private:
	uint			seed;

public:
					glqRandom (void);
	explicit		glqRandom (const uint seed);

	uint			GetSeed (void) const;
	void			SetSeed (const uint seed);

	int				RandInt (void);
	int				RandInt (const int max);
	int				RandInt (const int min, const int max);
	float			RandFloat (void);
	float			RandFloat (const float max);
	float			RandFloat (const float min, const float max);
	float			CRandFloat (void);
};

INLINE glqRandom::glqRandom (void){

	this->seed = 0;
}

INLINE glqRandom::glqRandom (const uint seed){

	this->seed = seed;
}

INLINE int glqRandom::RandInt (void){

	seed = seed * 214013 + 2531011;

	return ((seed >> 16) & 0x7FFF);
}

INLINE int glqRandom::RandInt (const int max){

	if (max <= 0)
		return 0;

	return (RandInt() % (max + 1));
}

INLINE int glqRandom::RandInt (const int min, const int max){

	if (max - min <= 0)
		return 0;

	return (RandInt() % (max - min + 1) + min);
}

INLINE float glqRandom::RandFloat (void){

	seed = seed * 214013 + 2531011;

	return (((seed >> 16) & 0x7FFF) * (1.0f / 32767.0f));
}

INLINE float glqRandom::RandFloat (const float max){

	return (RandFloat() * max);
}

INLINE float glqRandom::RandFloat (const float min, const float max){

	return (RandFloat() * (max - min) + min);
}

INLINE float glqRandom::CRandFloat (void){

	return (RandFloat() * 2.0f - 1.0f);
}


#endif	// __MATH_RANDOM_H__